<?php

/*

  Action - Attack	$3

  +$2
  Each other player reveals cards from the top of his deck until he reveals a Victory or Curse card. He puts it on top and discards the other revealed cards.

 */

class FortuneTeller extends Card implements iAction, iKingdom, iAttack, iCornucopia {

    public function __construct() {
        parent::__construct("Fortune Teller", 3);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "+$2",
            "Each other player reveals cards from the top of his deck until he reveals a Victory or Curse card. He puts it on top and discards the other revealed cards.");
    }
    
    public function play(Game $game, $isRealCard) {
        $game->attack($this);
        $game->addMoney(new Price(2));
         ScreenDisplay::addScreenMessage($game, true, "get +2$", "gets +2$");


        $names = $game->getOtherPlayersNames(true);
        $good_card = null;
        foreach ($names as $name) {
            $card = $game->peekCardFromDrawDeck($name);
            $discardCards = array();
            while ($card != null) {

                if ($card instanceof iVictory || $card instanceof iCurse) {
                    $good_card = $card;
                    break;
                } else {
                    $card = $game->removeCardFromDrawDeck($name);
                    $discardCards[] = $card;
                }

                $card = $game->peekCardFromDrawDeck($name);
            }

             ScreenDisplay::addScreenMessage($game, true, "reveal " . nicePrint($discardCards) . " and leave " . nicePrint($good_card) . " on top of your deck", 
                    "reveals " . nicePrint($discardCards) . " and leaves " . nicePrint($good_card) . " on top of his deck", $name);
            
            $game->discardTempDiscardCards($discardCards, $name);
        }

        $game->cardActionFinished();
        return true;
    }

}

?>